<?php
	class ProfileCtl extends BaseCtl {
		
		public function ProfileCtl() {
			parent::BaseCtl();
		}
		
	    public function isPostback(){
	    	return 'profile' == $this->getPost('pagename');
	    }
	
	    public function loadData(){
	    	$form = $this->getProfileForm();
		
	    	$form->setLogin($this->getPost('login'));
			$form->setName($this->getPost('name'));
			
			$form->setConnect('yes' == $this->getPost('connect'));
			$form->setAdmin('yes' == $this->getPost('admin'));
			
			$form->setEmail($this->getPost('email'));
			$form->setSendEmail('on' == $this->getPost('sendEmail'));
	    }
	    
	    public function submit(){
	    	try {
	    		// get the parameters
	    		$form = $this->getProfileForm();
	    		$s = HtmlUtil::getSessionUser(); 
	    		
	    		$user = $s->getUser();
	    		$id = $user->getId();
	    		
	    		$login = $form->getLogin();
	    		$name = $form->getName();
	    		$email = $form->getEmail();
	    		$sendEmail = $form->isSendEmail();
	    		
	    		$service = new Service();
	    		$service->updateProfile($id, $login, $name, $email, $sendEmail);
	    		
	    		// fill them out and operate the changes
	    		// retrieve the user and again put it in the session user
	    		$us = $service->getUserById($id);
	    		
	    		$s->setUser($us);
	    		
	    		// then go back to albums
	    		$this->redirect('albums.php');
	    	}
	    	catch(Exception $e){
	    		HtmlUtil::addError($e->getMessage());
	    	}
	    }
	    
	    public function cancel() {
	    	try {
	    		$this->redirect('albums.php');
	    	}
	    	catch(Exception $e){
	    		HtmlUtil::addError($e->getMessage());
	    	}
	    }
	    
	    public function password(){
	    	try {
	    		$form = $this->getChownPassForm(); 
	    		$form->clear();
	    		
	    		$this->redirect('chownpass.php');
	    	}
	    	catch(Exception $e){
	    		HtmlUtil::addError($e->getMessage());
	    	}
	    }
	
	} 
?>